import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({
	// 设置全局访问的state对象
	state:{
		// 需要访问的属性设置初始值
		userType:0,
		/*
		* login_status 用户的登录状态
		* 0 未登录
		* 1 认证了微信 为登录手机号
		* 2 登陆了手机号（以获取到token）
		*/ 
	   login_status:0,
	   payType:'alipayScan',//默认支付类型
	   navHeight:'88rpx',//导航栏高度
	   infoNumType:123,//一旦改变说明当前用户查看了未读消息
	   btnshow:true,//默认展示按钮（用作提交时检测使用）
	   configObj:{},//小程序整体文案动态配置
	   addrObj:{},//换成当前用户所在地址信息
	   userInfo:{},//用户信息
	   goldenArea:[],//黄金区域缓存
	   hClassArr:[],//用户粘性
	   deviceModel:'',
	   likeType:0,//分享次数
	   isShare:false,//记录是否分享
	   isTelGuide:0,//记录详情页面 ，是否弹出过 引导用户获取电话号码的弹窗(0 true 弹窗，1 false 不弹窗)
	   saleCode:null,//销售员的id
	   isChatMore:true,//记录用户是否第一次进入聊天列表，并弹出了查看更多，以后将不在弹出
	},
	// getters 实时监听state的值 有无发生改变
	getters:{
		userType(state){
			if(uni.getStorageSync('userType')){
			  state.userType=uni.getStorageSync('userType')
			  }
			return state.userType
		},
		login_status(state){
			if(uni.getStorageSync('login_status')){
			  state.login_status=uni.getStorageSync('login_status')
			  }
			return state.login_status
		},
		payType(state){
			if(uni.getStorageSync('payType')){
			  state.login_status=uni.getStorageSync('payType')
			  }
			return state.payType
		},
		navHeight(state){
			return state.navHeight
		},
		infoNumType(state){
			return state.infoNumType
		},
		btnshow(state){
			if(uni.getStorageSync('btnshow')){
			  state.btnshow=uni.getStorageSync('btnshow')
			  }
			return state.btnshow
		},
		configObj(state){
			if(uni.getStorageSync('configObj')){
			  state.configObj=uni.getStorageSync('configObj')
			  }
			return state.configObj
		},
		addrObj(state){
			// if(uni.getStorageSync('addrObj')){
			//   state.addrObj=uni.getStorageSync('addrObj')
			//   }
			return state.addrObj
		},
		userInfo(state){
			if(uni.getStorageSync('userInfo')){
			  state.userInfo=uni.getStorageSync('userInfo')
			  }
			return state.userInfo
		},
		goldenArea(state){
			if(uni.getStorageSync('goldenArea')){
			  state.goldenArea=uni.getStorageSync('goldenArea')
			  }
			return state.goldenArea
		},
		hClassArr(state){
			if(uni.getStorageSync('hClassArr')){
			  state.hClassArr=uni.getStorageSync('hClassArr')
			  }
			return state.hClassArr
		},
		deviceModel(state){
			if(uni.getStorageSync('deviceModel')){
			  state.deviceModel=uni.getStorageSync('deviceModel')
			  }
			return state.deviceModel
		},
		likeType(state){
			if(uni.getStorageSync('likeType')){
			  state.likeType=uni.getStorageSync('likeType')
			  }
			return state.likeType
		},
		isShare(state){
			if(uni.getStorageSync('isShare')){
			  state.isShare=uni.getStorageSync('isShare')
			  }
			return state.isShare
		},
		isTelGuide(state){
			if(uni.getStorageSync('isTelGuide')){
			  state.isTelGuide=uni.getStorageSync('isTelGuide')
			  }
			return state.isTelGuide
		},
		saleCode(state){
			if(uni.getStorageSync('saleCode')){
			  state.saleCode=uni.getStorageSync('saleCode')
			  }
			return state.saleCode
		},
		isChatMore(state){
			if(uni.getStorageSync('isChatMore')){
			  state.isChatMore=uni.getStorageSync('isChatMore')
			  }
			return state.isChatMore
		},
		
	},
	// 修改state内的参数 (要修改store中的值唯一的方法就是使用mutation的commit来修改)
	mutations:{
		setUserType(state,num){
			state.userType = num
			uni.setStorageSync('userType',num)
		},
		setLoginStatu(state,num){
			state.login_status = num
			uni.setStorageSync('login_status',num)
		},
		setPayType(state,type){
			state.payType = type
			uni.setStorageSync('payType',type)
		},
		setInfoNumType(state,num){
			state.infoNumType = num
		},
		setbtnshow(state,type){
			state.btnshow = type
			uni.setStorageSync('btnshow',type)
		},
		setConfigObj(state,type){
			state.configObj = type
			uni.setStorageSync('configObj',type)
		},
		setAddrObj(state,data){
			state.addrObj = data
			// uni.setStorageSync('addrObj',data)
		},
		setUserInfo(state,data){
			state.userInfo = data
			uni.setStorageSync('userInfo',data)
		},
		setGoldenArea(state,data){
			state.goldenArea = data
			uni.setStorageSync('goldenArea',data)
		},
		setHClassArr(state,data){
			state.hClassArr = data
			uni.setStorageSync('hClassArr',data)
		},
		setdeviceModel(state,data){
			state.deviceModel = data
			uni.setStorageSync('deviceModel',data)
		},
		likeType(state,data){
			state.likeType = data
			uni.setStorageSync('likeType',data)
		},
		isShare(state,data){
			state.isShare = data
			uni.setStorageSync('isShare',data)
		},
		isTelGuide(state,data){
			state.isTelGuide = data
			uni.setStorageSync('isTelGuide',data)
		},
		saleCode(state,data){
			state.saleCode = data
			uni.setStorageSync('saleCode',data)
		},
		isChatMore(state,data){
			state.isChatMore = data
			uni.setStorageSync('isChatMore',data)
		},
		
	},
	/*
	*Action 类似于 mutation，不同在于：
	*Action 提交的是 mutation，而不是直接变更状态。
	*Action 可以包含任意异步操作。
	* 使用dispatch来提交actions
	*/
   actions:{
		setUserTypes(context,num){
		   context.commit('setUserType',Number(num))
		},
		setLoginStatus(context,num){
		   context.commit('setLoginStatu',Number(num))
		},
		setPayTypes(context,type){
		   context.commit('setPayType',type)
		},
		setInfoNumType(context,num){
		   context.commit('setInfoNumType',num)
		},
		setbtnshows(context,type){
			context.commit('setbtnshow',type)
		},
		setConfigObjs(context,type){
			context.commit('setConfigObj',type)
		},
		setAddrObjs(context,data){
			context.commit('setAddrObj',data)
		},
		setUserInfos(context,data){
			context.commit('setUserInfo',data)
		},
		setGoldenArea(context,data){
			context.commit('setGoldenArea',data)
		},
		setHClassArr(context,data){
			context.commit('setHClassArr',data)
		},
		setdeviceModel(context,data){
			context.commit('setdeviceModel',data)
		},
		setlikeType(context,data){
			context.commit('likeType',data)
		},
		setIsShare(context,data){
			context.commit('isShare',data)
		},
		setIsTelGuide(context,data){
			context.commit('isTelGuide',data)
		},
		setSaleCode(context,data){
			context.commit('saleCode',data)
		},
		setIsChatMore(context,data){
			context.commit('isChatMore',data)
		},
		
   }
	
})